package com.zy.bean.bo.script;

import com.zy.bean.po.LiteflowScript;
import com.zy.enums.ScriptLanguageEnum;
import com.zy.enums.ScriptTypeEnum;
import com.zy.util.SnowflakeIdWorker;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
import org.apache.commons.lang3.ObjectUtils;

/**
 * @author : hanhuafeng
 * @date : 2023/11/13 17:12
 */
@Data
public class LiteflowScriptBo {
    /**
     * 脚本id
     */
    private String scriptId;

    /**
     * 脚本名称
     */
    @NotEmpty(message = "脚本名称不能为空")
    private String scriptName;

    /**
     * 脚本内容
     */
    @NotEmpty(message = "脚本内容不能为空")
    private String scriptData;

    /**
     * 脚本类型
     */
    @NotEmpty(message = "脚本类型不能为空")
    private ScriptTypeEnum scriptType;

    /**
     * 脚本语言
     */
    @NotEmpty(message = "脚本语言不能为空")
    private ScriptLanguageEnum scriptLanguage;

    public static LiteflowScript toPo(LiteflowScriptBo liteflowScriptBo) {
        LiteflowScript liteflowScript = new LiteflowScript();
        String code = SnowflakeIdWorker.getUuid();
        liteflowScript.setCode(code);
        if (ObjectUtils.isNotEmpty(liteflowScriptBo.getScriptId())) {
            liteflowScript.setScriptId(liteflowScriptBo.getScriptId());
        } else {
            liteflowScript.setScriptId(code);
        }
        liteflowScript.setScriptName(liteflowScriptBo.getScriptName());
        liteflowScript.setScriptData(liteflowScriptBo.getScriptData());
        liteflowScript.setScriptType(liteflowScriptBo.getScriptType().getType());
        liteflowScript.setScriptLanguage(liteflowScriptBo.getScriptLanguage().getLanguage());
        return liteflowScript;
    }
}
